#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <stdlib.h>

void tree(int depth, char* path)
{
    if (depth > 5)
        return;

    DIR *dir = opendir(path);

    while (1)
    {
        int d = depth;

        struct dirent *dire = readdir(dir);
        if (dire == NULL)
            break;
        switch (dire->d_type)
        {
            case DT_DIR:
                if (dire->d_name[0] == '.')
                    break;
                
                while (d--)
                    printf("  ");
                printf("%s\n", dire->d_name);

                char* path2 = (char*)malloc(sizeof(char)*256);
                strcpy(path2, path);
                strcat(path2, "/");
                strcat(path2, dire->d_name);

                tree(depth+1, path2);
                free(path2);
                break;

            case DT_REG:
                while (d--)
                    printf("  ");
                printf("%s\n", dire->d_name);
                break;
        }
    }

    closedir(dir);
}


int main(int argc, char *argv[])
{
    printf(".\n");
    char path[256] = ".";
    if (argc > 1)
        strcpy(path, argv[1]);
    tree(1, path);
}